<?php
  error_reporting(-1);
  
  include( "./includes/config.php" ); 
  //include "./includes/dogtagsimg.php";
  include "./includes/dogtagsimg1.php";
      
  if (!empty($_COOKIE['sid'])) 
  {
		session_id($_COOKIE['sid']);// check session id in cookies
  }

session_start();

include './classes/Auth.class.php';
include './classes/mysql.class.php';

 $action = isset( $_GET['action'] ) ? $_GET['action'] : "";
  
if (Battlelog\User::isAuthorized())
{
   switch ( $action ) 
   {
	case 'overview':
		overview($lang);
		break;
	 case 'leaderboard':
		Leaderboard($lang);
		break;
	case 'serverbrowser':
		serverbrowser($lang);
		require_once("./includes/comcenter.php");
		break;
	case 'login':
		login($lang);
		break;
	case 'logout':
		logout();
		break;
	case 'register':
		register($lang);
		break;
	case 'dogtagsB':
		dogtagsB($lang);
		break;
	case 'dogtagsA':
		dogtagsA($lang);
		break;
	case 'settings':
		settings($lang);
		break;
	case 'savesettings':
		savesettings($lang);
		break;
	case 'instructions':
		instructions($lang);
		break;
	case 'battle':
		battle($lang);
		break;
	case 'downloads':
		downloads($lang);
		break;
	case 'awards':
		awards($lang);
		break;
	case 'vehicles':
		vehicles($lang);
		break;
	case 'weapons':
		weapons($lang);
		break;
	case 'weaponUnlocks':
		weaponUnlocks($lang);
		break;		
	case 'equipment':
		equipment($lang);
		break;	
	case 'avatarloading':
		avatarloading($lang);
		break;
	case 'assignments':
		assignments($lang);
		break;
	default:
		overview($lang);
	}
}
else
{
	switch ( $action ) 
   {
	case 'login':
		login($lang);
		break;
	case 'logout':
		logout();
		break;
	case 'register':
		register($lang);
		break;
	default:
		instructions1($lang);
	}
}

function login($lang) 
{
  open_page("Battlelog / Battlefield 3", "Log in", $lang ['LogIn'], false);
  get_page()->begin_center($lang);
  include "./pages/login.php";
  get_page()->end_center();
  include "./includes/scooter.php";
  close_page();     
}

function logout() 
{
	$pid = Battlelog\User::UserPID();
	$battlelog = new Battlelog\Mysql();
	$battlelog->UpdateUserTimeLogout($pid,'-500');
	
	setcookie("sid", "");
	if (!empty($_SESSION["user_id"]))
	{
	    unset($_SESSION["user_id"]);
    }
	header( "Location: ./" );
}

function register($lang) 
{
  open_page("Battlelog / Battlefield 3", "Sign up", $lang ['SignUp'], false);
  get_page()->begin_center($lang);
  include "./pages/register.php";
  get_page()->end_center();
  include "./includes/scooter.php";
  close_page();     
}

function Leaderboard($lang) 
{
  open_page("Battlelog / Battlefield 3", "Leaderboard", $lang ['Leaderboard'], true);
  get_page()->begin_center($lang);
  include "./pages/leaderboard.php";
  get_page()->end_center();
  include "./includes/scooter.php";
  close_page();     
}

function awards($lang) 
{
   open_page("Battlelog / Battlefield 3", "Awards", $lang ['Awards'], true);
   include "./includes/header.php";
   get_page()->begin_center($lang);
   include "./pages/awards.php";
   get_page()->end_center();
   include "./includes/scooter.php";
   close_page();     
}

function vehicles($lang) 
{
   open_page("Battlelog / Battlefield 3", "Vehicles", $lang ['Stats'], true);
   include "./includes/header.php";
   get_page()->begin_center($lang);
   include "./pages/vehicles.php";
   get_page()->end_center();
   include "./includes/scooter.php";
   close_page();     
}

function weapons($lang) 
{
   open_page("Battlelog / Battlefield 3", "Weapons", $lang ['Stats'], true);
   include "./includes/header.php";
   get_page()->begin_center($lang);
   include "./pages/weapons.php";
   get_page()->end_center();
   include "./includes/scooter.php";
   close_page();     
}

function weaponUnlocks($lang) 
{
   open_page("Battlelog / battlefield 3", "WeaponUnlocks", $lang['WeaponUnlocks'], true);
   include "./includes/header.php";
   get_page()->begin_center($lang);
   include "./pages/weaponUnlocks.php";
   get_page()->end_center();
   include "./includes/scooter.php";
   close_page();     
}

function equipment($lang) 
{
   open_page("Battlelog / Battlefield 3", "Equipment", $lang ['Stats'], true);
   include "./includes/header.php";
   get_page()->begin_center($lang);
   include "./pages/equipment.php";
   get_page()->end_center();
   include "./includes/scooter.php";
   close_page();     
}

function dogtagsB($lang) 
{
  open_page("Battlelog / Battlefield 3", "Dog Tags", $lang ['DogTags'], true);
  get_page()->begin_center($lang);
  include "./pages/dogtagsB.php";
  get_page()->end_center();
  include "./includes/scooter.php";
  close_page();     
}

function dogtagsA($lang) 
{
  open_page("Battlelog / Battlefield 3", "Dog Tags", $lang ['DogTags'], true);
  get_page()->begin_center($lang);
  include "./pages/dogtagsA.php";
  get_page()->end_center();
  include "./includes/scooter.php";
  close_page();     
}

function serverbrowser($lang) 
{
  open_page("Battlelog / Battlefield 3", "Server Browser", $lang ['Multiplayer'], true);
  include("./includes/loadTracker.php");
  get_page()->begin_center($lang);
  include "./pages/serverbrowser.php";
  get_page()->end_center();
  include "./includes/scooter.php";
  close_page();     
 
}

function overview($lang) 
{
  open_page("Battlelog / Battlefield 3", "Overview", $lang ['Overview'], true);
  get_page()->begin_center($lang);
  include "./pages/overview.php";
  get_page()->end_center();
  include "./includes/scooter.php";
  close_page();     
}

function settings($lang) 
{
   open_page("Battlelog / Battlefield 3", "Settings", $lang ['settings'], true);
   get_page()->begin_center($lang);
   include "./pages/settings.php";
   get_page()->end_center();
   include "./includes/scooter.php";
   close_page();     
}

function assignments($lang) 
{
   open_page("Battlelog / Battlefield 3", "Assignments", $lang ['Assignments'], true);
   get_page()->begin_center($lang);
   include "./pages/assignments.php";
   get_page()->end_center();
   include "./includes/scooter.php";
   close_page();     
}

function savesettings() 
{
	$dta = Battlelog\User::UserDTA();
	$dtb = Battlelog\User::UserDTB();
	$pid = Battlelog\User::UserPID();
	
	$clntg = $_POST['profile-edit-clantag'];
	Battlelog\User::UpdateUserCLNTG($clntg);
	$battlelog = new Battlelog\Mysql();
	$battlelog->UpdateClantag($pid, $clntg, $dta, $dtb);
    header( "Location: index.php" );
}

function avatarloading() 
{
	
    header( "Location: index.php" );
}

function instructions($lang) 
{
   open_page("Battlelog / Battlefield 3", "Instructions", $lang ['SM0'], true);
   include "./includes/header.php";
   get_page()->begin_center();
   include "./pages/instructions.php";
   get_page()->end_center();
   include "./includes/scooter.php";
   close_page();     
}

function instructions1($lang) 
{
  open_page("Battlelog / Battlefield 3", "Instructions", $lang ['SM0'], false);
  get_page()->begin_center($lang);
  include "./pages/instructions.php";
  get_page()->end_center();
  include "./includes/scooter.php";
  close_page();  
}

function battle($lang) 
{
  open_page("Battlelog / Battlefield 3", "Battle", $lang ['LU'], true);
  get_page()->begin_center($lang);
  include "./pages/battle.php";
  get_page()->end_center();
  include "./includes/scooter.php";
  close_page();  
}

function downloads($lang) 
{
   open_page("Battlelog / Battlefield 3","Downloads",$lang ['Downloads'],  true);
   include "./includes/header.php";
   get_page()->begin_center();
   include "./pages/downloads.php";
   get_page()->end_center();
   include "./includes/scooter.php";
   close_page();     
}

  
?>